#coding=utf-8
from bottle import request, response
from config import config

SESSION_KEY = config.SESSION_KEY

def getsession():
	return request.get_cookie('session', secret=SESSION_KEY)

def get(key):
	g = getsession()
	if g:
		return g.get(key)
	return ''

def set(key, value=""):
	v = getsession()
	if v is None:
		v = {}
	v[key] = value
	if len(str(v))>=4*1024:
		print 'cookit to max'
	response.set_cookie('session',v , secret=SESSION_KEY)

def pop(key):
	v = getsession()
	if v is not None:
		if v.get(key) is not None:
			v.pop(key)
			response.set_cookie('session',v , secret=SESSION_KEY)
